package com.one.controller;


import com.one.annotation.RequestPermission;
import com.one.annotation.RequestUser;
import com.one.bean.Ticket;
import com.one.service.OrderFlashSaleService;
import com.one.util.RequestReturn;
import com.one.vo.ProductParamVo;
import com.one.vo.UserVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * Create on 2022-01-20
 * <p>
 * Author: LiangWei
 * <p>
 * Description:
 **/
@Api(tags = "K抢购操作入口")
@RestController
@Slf4j
public class OrderFlashSaleController {
    @Autowired
    private OrderFlashSaleService orderFlashSaleService;
    /**
     *  下单抢购业务
     */
    @ApiOperation(value = "下单抢购")
    @RequestPermission
    @PostMapping("/orderAndRushBuy")
    public RequestReturn<String> orderAndRushBuy(@RequestBody ProductParamVo productParamVo){
        log.info("ddd请求参数：{}",productParamVo);
        return orderFlashSaleService.orderFlashSale(productParamVo);
    }

    /**
     *  微信支付业务
     */
    @ApiOperation(value = "微信支付")
    @GetMapping("/wechatPay")
    @RequestPermission
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", required = true, value = "订单编号"),
            @ApiImplicitParam(name = "consigneeId", required = true, value = "收货地址id"),
            @ApiImplicitParam(name = "ticketId", required = true, value = "优惠卷id（0,1,2,3）")
    })
    public RequestReturn<String> wechatPay(@ApiIgnore @RequestUser UserVo userVo,
                                           @RequestParam String orderNo,
                                           @RequestParam Integer consigneeId,
                                           @RequestParam Integer ticketId,
                                           @ApiIgnore @RequestHeader String token) {
        return orderFlashSaleService.wxPay(userVo.getUserId(),orderNo,consigneeId,ticketId,token);
    }

    /**
     *  普通下单业务
     */
    @ApiOperation(value = "普通下单")
    @PostMapping("/coOrder")
    public RequestReturn<String> coOrder(@RequestBody List<ProductParamVo> productParamVoList){
        return orderFlashSaleService.commonOrder(productParamVoList);
    }
}
